package net.maku.module.organization.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.module.organization.convert.PositionConvert;
import net.maku.module.organization.vo.PositionVO;
import net.maku.newbase.NewBaseController;
import net.maku.module.organization.entity.PositionEntity;
import net.maku.module.organization.service.PositionService;
import net.maku.newbase.NewQuery;
import net.maku.newbase.PageParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 职位
 *
 * @author JYL
 */
@RestController
@RequestMapping("nb/position")
@Tag(name = "职位")
@AllArgsConstructor
public class PositionController extends NewBaseController<PositionService, PositionEntity> {

    @GetMapping("page")
    @Operation(summary = "分页")
    public Result<PageResult<PositionVO>> page(PageParam page, NewQuery query){
        LambdaQueryWrapper<PositionEntity> select = new LambdaQueryWrapper<>();

        IPage<PositionEntity> iPage = entityService.page(page.b(), select);
        return Result.ok(new PageResult<>(PositionConvert.INSTANCE.convertList(iPage.getRecords()), iPage.getTotal()));
    }

    @Operation(summary = "全部")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result list() {
        List<PositionEntity> list = entityService.list();

        return Result.ok(PositionConvert.INSTANCE.convertList(list));
    }

}
